<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
    <!-- Loading Bootstrap -->
    <link href="/static/admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
    <!-- Loading Flat UI -->
    <link href="/static/admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
    <link href="/static/admin/Flat/docs/assets/css/demo.css" rel="stylesheet">
    <link rel="shortcut icon" href="/static/admin/Flat/img/favicon.ico">
    <!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
    <!--[if lt IE 9]>
    <script src="dist/js/vendor/html5shiv.js"></script>
    <script src="dist/js/vendor/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div>
    <button onclick="addAuthModal(0)" class="btn btn-sm btn-warning">添加顶级权限</button>
    <!--<a href="/admin/authrule/create" class="btn btn-sm btn-info">添加新权限</a>-->
    <a href="/admin/authrule/onekeycreate" class="btn btn-sm btn-info">一键添加权限规则</a>
</div>
<table class="table table-hover">
    <tr class="active">
        <th width="150">id</th>
        <th>权限名</th>
        <th>权限规则（模块/控制器/方法）</th>
        <th>操作</th>
    </tr>
    {volist name="treeDatas" id="ruleData"}
    <tr>
        <td>{$ruleData.id}</td>
        <td>{$ruleData._name}</td>
        <td>{$ruleData.name}</td>
        <td>
            <button onclick="addAuthModal({$ruleData.id})" class="btn btn-sm btn-warning">添加子权限</button>
            <a href="/admin/authrule/{$ruleData.id}/edit" class="btn btn-sm btn-info">编辑</a>
            <a onclick="deleteauthrule({$ruleData.id});return false;" class="btn btn-sm btn-danger">删除</a>
        </td>
    </tr>
    {/volist}
</table>

<script src="https://cdn.bootcss.com/jquery/2.1.0/jquery.min.js"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
<!--子权限-->
<!--模态框-->
<div class="modal fade" id="addAuthModal" tabindex="-1" role="dialog" aria-labelledby="addAuthModal">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="addAuthModal">添加子权限</h4>
            </div>
            <form action="/admin/authrule" method="post">
                <div class="modal-body">
                    <input type="hidden" name="pid" id="pid" value="">
                    <div class="form-group">
                        <label for="title" class="control-label">权限名</label>
                        <input type="text" class="form-control" id="title" placeholder="请输入权限名称" name="title">
                    </div>
                    <div class="form-group">
                        <label for="name" class="control-label">权限规则(模块/控制器/方法):</label>
                        <input required id="name" class="form-control" type="text" placeholder="权限规则(模块/控制器/方法)"
                               name="name">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">确认</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    function addAuthModal(id) {
        $('#pid').val(id);
        $('#title').val('');
        $('#name').val('');
        $('#addAuthModal').modal();
    }
</script>

<!--删除-->
<script>
    function deleteauthrule(id) {
        if (!confirm('确认操作，此操作不可逆?')) {
            return;
        }
        $.ajax({
                type: "DELETE", //提交方式
                url: "/admin/authrule/" + id,//路径
                dataType: 'Json',
                success: function (res) {
                    if (res.status) {
                        alert(res.msg);
                        location.reload()
                    } else {
                        alert(res.msg);
                    }
                }
            }
        )
    }
</script>
</body>
</html>
